package com.example.controller.sys;

import java.util.Arrays;

import com.sun.org.apache.xpath.internal.operations.Bool;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.vo.ResultVo;
import com.github.pagehelper.PageInfo;
import com.example.pojo.ContactsGroup;
import com.example.service.IContactsGroupService;
import io.swagger.annotations.Api;
/**
 * <p>
 * 联系人分组 前端控制器
 * </p>
 *
 * @author wsl
 * @since 2022-05-14
 */
@RestController
@RequestMapping("/sys/contacts-groups")
@Api(tags = "联系人分组",value = "")
@CrossOrigin(allowCredentials = "true")
public class ContactsGroupController {

    @Autowired
    private IContactsGroupService contactsGroupService;

    @ApiOperation(value = "查询联系人分组")
    @GetMapping("/query")
    public ResultVo getUserContactsGroup(Integer empId) {
        return contactsGroupService.getUserContactsGroup(empId);
    }

    @ApiOperation(value = "新增联系人分组")
    @PostMapping("/add")
    public ResultVo addContactsGroup(@RequestBody ContactsGroup contactsGroup) {
        if(contactsGroupService.save(contactsGroup)){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }

    @ApiOperation(value = "修改联系人分组")
    @PutMapping("/update")
    public ResultVo updateContactsGroup(@RequestBody ContactsGroup contactsGroup) {
        if (contactsGroupService.updateById(contactsGroup)) {
            return ResultVo.success("修改成功。");
        }
        return ResultVo.error("修改失败!");
    }

    @ApiOperation(value = "删除联系人分组")
    @DeleteMapping("/delete")
    public ResultVo deleteContactsGroup(Integer[] ids,Integer empId){
        return contactsGroupService.deleteContactsGroup(ids,empId);
    }

    @ApiOperation(value = "是否已存在同名组")
    @GetMapping("/has-same-name")
    public Boolean hasSameNameGroup(Integer id,@RequestParam("groupName")String groupName){
        return contactsGroupService.hasSameNameGroup(id,groupName);
    }
}
